home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / utilities / icon_1.0 / source / icon.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  26KB  |  1,275 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf Barthel & MXM
  4.  *
  5.  *    Name .....: Icon.c
  6.  *    Created ..: Friday 10-May-91 16:58
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    10-May-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15.     /* A quick set of file types we are able to provide icons for. */
  16.  
  17. enum    {    TYPE_DIR,TYPE_FILE,TYPE_ICON,
  18.         TYPE_TEXT,
  19.         TYPE_C,TYPE_H,
  20.         TYPE_ASM,TYPE_I,
  21.         TYPE_MOD,
  22.         TYPE_REXX,
  23.         TYPE_BASIC,
  24.         TYPE_TEX,TYPE_METAFONT,TYPE_GF,TYPE_TEXFONT,TYPE_TEXDVI,TYPE_FLIB,
  25.         TYPE_OLDMANX,TYPE_NEWMANX,TYPE_OLDMANXLIB,TYPE_NEWMANXLIB,
  26.         TYPE_OBJECT,TYPE_LIB,
  27.         TYPE_EXECUTABLE,
  28.         TYPE_LIBRARY,TYPE_DEVICE,TYPE_FILESYS,TYPE_HANDLER,
  29.         TYPE_GIF,TYPE_ILBM,TYPE_ANIM,TYPE_8SVX,TYPE_SMUS,TYPE_FTXT,TYPE_PREFS,TYPE_TERM,
  30.         TYPE_IMPLODER,TYPE_POWERPACKER,
  31.         TYPE_ARC,TYPE_LHARC,TYPE_ZOO,TYPE_ZIP,TYPE_DMS,TYPE_WARP,TYPE_ZOOM,
  32.     };
  33.  
  34.     /* Name of the global handshake port. */
  35.  
  36. #define PORTNAME    "Icon Rendezvous"
  37.  
  38.     /* Library vector offsets for a bunch of routines. */
  39.  
  40. #define EXAMINE        -102
  41. #define EXNEXT        -108
  42. #define OPEN        -30
  43. #define CLEARMENUSTRIP    -54
  44.  
  45.     /* This structure describes the global handshake port. */
  46.  
  47. struct IconPort
  48. {
  49.     struct MsgPort     VanillaPort;
  50.  
  51.     BPTR         Segment;
  52.     VOID        (*Remove)();
  53. };
  54.  
  55.     /* A structure containing both a file name suffix and the
  56.      * approriate file type.
  57.      */
  58.  
  59. struct Suffix
  60. {
  61.     UBYTE    *Name;
  62.     UBYTE     Type;
  63. };
  64.  
  65.     /* A structure containing an icon file name and a special
  66.      * purpose flag.
  67.      */
  68.  
  69. struct NameInfo
  70. {
  71.     UBYTE    *Name;
  72.     BYTE     IsPresent;
  73. };
  74.  
  75.     /* A table of valid ASCII characters (7 bits). */
  76.  
  77. BYTE ValidTab[256] =
  78. {
  79.     0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,
  80.     0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
  81.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  82.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  83.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  84.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  85.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  86.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  87.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  88.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  89.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  90.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  91.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  92.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  93.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  94.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  95. };
  96.  
  97.     /* A table of clearly invalid ASCII characters (8 bits). */
  98.  
  99. BYTE InvalidTab[256] =
  100. {
  101.     1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,
  102.     1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,
  103.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  104.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  105.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  106.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  107.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  108.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  109.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  110.     1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,
  111.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  112.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  113.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  114.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  115.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  116.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  117. };
  118.  
  119.     /* Some file name suffixes for text files and the approriate
  120.      * file types.
  121.      */
  122.  
  123. struct Suffix TextSuffix[] =
  124. {
  125.     ".C",    TYPE_C,
  126.     ".CP",    TYPE_C,
  127.     ".CC",    TYPE_C,
  128.     ".H",    TYPE_H,
  129.     ".ASM",    TYPE_ASM,
  130.     ".A",    TYPE_ASM,
  131.     ".S",    TYPE_ASM,
  132.     ".I",    TYPE_I,
  133.     ".BAS",    TYPE_BASIC,
  134.     ".GFA",    TYPE_BASIC,
  135.     ".REXX",TYPE_REXX,
  136.     ".CED",    TYPE_REXX,
  137.     ".VLT",    TYPE_REXX,
  138.     ".CPR",    TYPE_REXX,
  139.     ".TxEd",TYPE_REXX,
  140.     ".TEX",    TYPE_TEX,
  141.     ".STY",    TYPE_TEX,
  142.     ".MF",    TYPE_METAFONT,
  143.     ".MOD",    TYPE_MOD,
  144.     ".DEF",    TYPE_MOD
  145. };
  146.  
  147.     /* Some more file name suffixes for executable files and the
  148.      * approriate file types.
  149.      */
  150.  
  151. struct Suffix ExecutableSuffix[] =
  152. {
  153.     ".device",    TYPE_DEVICE,
  154.     ".library",    TYPE_LIBRARY,
  155.     "FileSystem",    TYPE_FILESYS,
  156.     "Handler",    TYPE_HANDLER
  157. };
  158.  
  159.     /* This list contains the names of all icon files which can be
  160.      * attached to the files to be identified. The flag byte indicates
  161.      * whether an icon is available or not.
  162.      */
  163.  
  164. struct NameInfo NameInfo[] =
  165. {
  166.     NULL,        FALSE,
  167.     NULL,        FALSE,
  168.     NULL,        FALSE,
  169.     "text",        FALSE,
  170.     "c",        FALSE,
  171.     "h",        FALSE,
  172.     "asm",        FALSE,
  173.     "i",        FALSE,
  174.     "mod",        FALSE,
  175.     "rexx",        FALSE,
  176.     "basic",    FALSE,
  177.     "tex",        FALSE,
  178.     "metafont",    FALSE,
  179.     "gf",        FALSE,
  180.     "pk",        FALSE,
  181.     "dvi",        FALSE,
  182.     "flib",        FALSE,
  183.     "manx3object",    FALSE,
  184.     "manx5object",    FALSE,
  185.     "manx3lib",    FALSE,
  186.     "manx5lib",    FALSE,
  187.     "object",    FALSE,
  188.     "lib",        FALSE,
  189.     NULL,        FALSE,
  190.     "library",    FALSE,
  191.     "device",    FALSE,
  192.     "filesys",    FALSE,
  193.     "handler",    FALSE,
  194.     "gif",        FALSE,
  195.     "pic",        FALSE,
  196.     "anim",        FALSE,
  197.     "sound",    FALSE,
  198.     "score",    FALSE,
  199.     "ftxt",        FALSE,
  200.     "pref",        FALSE,
  201.     "term",        FALSE,
  202.     "imploder",    FALSE,
  203.     "powerpacker",    FALSE,
  204.     "arc",        FALSE,
  205.     "lharc",    FALSE,
  206.     "zoo",        FALSE,
  207.     "zip",        FALSE,
  208.     "dms",        FALSE,
  209.     "warp",        FALSE,
  210.     "zoom",        FALSE
  211. };
  212.  
  213.     /* Prototypes for functions in this module and Bypass.asm */
  214.  
  215. extern LONG __asm    MyExamine(register __d1 BPTR FileLock,register __d2 struct FileInfoBlock *FileInfo);
  216. LONG __saveds __asm    NewExamine(register __d1 BPTR FileLock,register __d2 struct FileInfoBlock *FileInfo);
  217.  
  218. extern LONG __asm    MyExNext(register __d1 BPTR FileLock,register __d2 struct FileInfoBlock *FileInfo);
  219. LONG __saveds __asm    NewExNext(register __d1 BPTR FileLock,register __d2 struct FileInfoBlock *FileInfo);
  220.  
  221. extern BPTR __asm    MyOpen(register __d1 UBYTE *Name,register __d2 LONG Mode);
  222. BPTR __saveds __asm    NewOpen(register __d1 UBYTE *Name,register __d2 LONG Mode);
  223.  
  224. extern VOID __asm    MyClearMenuStrip(register __a0 struct Window *Window);
  225. VOID __saveds __asm    NewClearMenuStrip(register __a0 struct Window *Window);
  226.  
  227. VOID __saveds        RemoveIcon(VOID);
  228. BYTE            InstallIcon(VOID);
  229.  
  230. struct Node *        MyFindName(struct List *List,UBYTE *Name);
  231. UBYTE            Local2Upper(UBYTE c);
  232. UBYTE            StrCmp(UBYTE *a,UBYTE *b);
  233. VOID            DeleteNode(struct Node *Node);
  234. struct Node *        CreateNode(UBYTE *Name);
  235. VOID            AddName(UBYTE *FileName,UBYTE Type);
  236.  
  237. ULONG __saveds        Main(VOID);
  238.  
  239.     /* Global and shared library identifiers. */
  240.  
  241. struct ExecBase        *SysBase;
  242. struct DosLibrary    *DOSBase;
  243. struct IntuitionBase    *IntuitionBase;
  244.  
  245.     /* Pointers to the old library routines. */
  246.  
  247. APTR             OldExamine;
  248. APTR             OldExNext;
  249. APTR             OldOpen;
  250. APTR             OldClearMenuStrip;
  251.  
  252.     /* The list containing the files which do not have an icon and the
  253.      * access semaphore.
  254.      */
  255.  
  256. struct SignalSemaphore     NameSemaphore;
  257. struct List         NameList;
  258.  
  259.     /* The node being scanned. */
  260.  
  261. struct Node        *ScanNode;
  262.  
  263.     /* True if ExNext is to perform fake scanning, else false. */
  264.  
  265. BYTE             FakeScan;
  266.  
  267.     /* Global handshake port. */
  268.  
  269. struct IconPort        *IconPort;
  270.  
  271.     /* Main():
  272.      *
  273.      *    Program entry point.
  274.      */
  275.  
  276. ULONG __saveds
  277. Main()
  278. {
  279.     struct Process *ThisProcess;
  280.  
  281.         /* Set up SysBase. */
  282.  
  283.     SysBase = *(struct ExecBase **)4;
  284.  
  285.         /* Look who we are. */
  286.  
  287.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  288.  
  289.         /* Started from Shell? */
  290.  
  291.     if(ThisProcess -> pr_CLI)
  292.     {
  293.             /* Open the DOS library. */
  294.  
  295.         if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36))
  296.         {
  297.             Printf("\33[1m\33[33mIcon\33[31m © \33[0mCopyright 1991 by Olaf Barthel, ");
  298.  
  299.                 /* If the port is available remove an
  300.                  * already running `Icon'.
  301.                  */
  302.  
  303.             if(IconPort = (struct IconPort *)FindPort(PORTNAME))
  304.             {
  305.                 Flush(ThisProcess -> pr_COS);
  306.  
  307.                 Printf("Removing patch... ");
  308.  
  309.                 Flush(ThisProcess -> pr_COS);
  310.  
  311.                 Forbid();
  312.  
  313.                 IconPort -> Remove();
  314.  
  315.                 Permit();
  316.  
  317.                 Printf("done.\n");
  318.  
  319.                 CloseLibrary(DOSBase);
  320.             }
  321.             else
  322.             {
  323.                     /* Install `Icon'. */
  324.  
  325.                 Flush(ThisProcess -> pr_COS);
  326.  
  327.                 Printf("Installing patch... ");
  328.  
  329.                 Flush(ThisProcess -> pr_COS);
  330.  
  331.                 if(InstallIcon())
  332.                     Printf("done.\n");
  333.                 else
  334.                 {
  335.                     Printf("failed!\a\n");
  336.  
  337.                     CloseLibrary(DOSBase);
  338.                 }
  339.             }
  340.         }
  341.         else
  342.             return(RETURN_FAIL);
  343.     }
  344.     else
  345.     {
  346.         struct Message *Message;
  347.  
  348.             /* Wait for Workbench startup message. */
  349.  
  350.         Message = (struct Message *)WaitPort(&ThisProcess -> pr_MsgPort);
  351.  
  352.         Forbid();
  353.  
  354.             /* And reply it. */
  355.  
  356.         ReplyMsg(Message);
  357.     }
  358.  
  359.     return(RETURN_OK);
  360. }
  361.  
  362.     /* MyFindName(struct List *List,UBYTE *Name):
  363.      *
  364.      *    Find a node in a list, scan for the name ignoring
  365.      *    case.
  366.      */
  367.  
  368. struct Node *
  369. MyFindName(struct List *List,UBYTE *Name)
  370. {
  371.     struct Node *Node;
  372.  
  373.     Node = List -> lh_Head;
  374.  
  375.     while(Node -> ln_Succ)
  376.     {
  377.         if(!StrCmp(Node -> ln_Name,Name))
  378.             return(Node);
  379.  
  380.         Node = Node -> ln_Succ;
  381.     }
  382.  
  383.     return(NULL);
  384. }
  385.  
  386.     /* Rem